var APP = require("../../base/app");
var common = require("./common");
var aTreasure = require("./aTreasure");
var aHongBao = require("./aHongBao");
var aRandom = require("./aRandom");
var utils = require("../../utils/utils");
var ocrGml = require("../../utils/ocrGml");
var baoShuang = new APP("爆爽短剧", {
  interval: 10,
  maxRunCount: 30,
  storage: common.storage,
});
baoShuang.checkOpen = function () {
  for (var index = 0; index < 5; index++) {
    sleep(utils.getRandom(1.5, 3, 1000));
    var content = "开宝箱得红包";
    if (utils.existsTextStartsWith(content)) {
      return true;
    }
    var content = "跳过";
    if (utils.clickTextStartsWith(content)) {
      sleep(utils.getRandom(1.5, 5, 1000));
      var content = "狠心离开";
      if (utils.clickTextStartsWith(content)) {
        sleep(utils.getRandom(1.5, 5, 1000));
        return true;
      }
    }
    var content = "跳过";
    var OcrItem = ocrGml.captureExistOne(content, true);
    if (OcrItem) {
      utils.clickOcrItem(OcrItem);
      sleep(utils.getRandom(1.5, 5, 1000));
      var content = "狠心离开";
      var OcrItem = ocrGml.captureExistOne(content, true);
      if (OcrItem) {
        utils.clickOcrItem(OcrItem);
        sleep(utils.getRandom(1.5, 5, 1000));
        return true;
      }
    }
    var content = "狠心离开";
    var OcrItem = ocrGml.captureExistOne(content, true);
    if (OcrItem) {
      utils.clickOcrItem(OcrItem);
      sleep(utils.getRandom(1.5, 5, 1000));
      return true;
    }
  }
};
baoShuang.run = function () {
  this.checkOpen();
  aTreasure.flow();
  sleep(utils.getRandom(1.5, 3, 1000));
  aRandom.flow();
  sleep(utils.getRandom(1.5, 3, 1000));
  common.toTask();
  sleep(utils.getRandom(1.5, 3, 1000));
  aHongBao.flow();
  // return true;
};

module.exports = baoShuang;
